<?php
/**
 * Created by PhpStorm.
 * User: 闲道人阿力
 * Date: 2016/10/13
 * Time: 13:40
 */
defined('IN_WZ') or exit('No direct script access allowed');
class index{

    public function getnexttpl(){
        $array = array();
        $dir =  COREFRAME_ROOT."templates/".TPLID."/content/".$GLOBALS['d']."/";
        if (is_dir($dir)) {
            if ($dh = opendir($dir)) {
                while (($file = readdir($dh)) !== false) {
                    $t=array();
                    $temp['type'] = (filetype($dir . $file)=="dir"?"1":"0");
                    //echo "filename: $file : filetype: " . filetype($dir . $file) . "<br>";
                    $temp['filename']=$file ;
                    if($file!="." && $file!=".." && !($GLOBALS['d']=="" && $file=="mobile"))
                    array_push($array,$temp);
                } closedir($dh);
            }
        }
        echo json_encode($array);

    }


    public function sendmail(){
        load_function('sendmail');
        if(send_mail($GLOBALS['email'],$GLOBALS['subject'],$GLOBALS['body'])===false) {
            //MSG("发送错误");
            echo json_encode(array("status"=>1,"msg"=>"配置错误"));
            return ;
        }
        echo json_encode(array("status"=>0));
    }


    public function sendmailaliyun(){
        $send = load_class("Mail","api");
        $send->send($GLOBALS['email'],$GLOBALS['subject'],$GLOBALS['body']);
        echo json_encode(array("status"=>0));
    }

    public function saveziduan(){
        $mydb = load_class("mydb","api");

        $table = $GLOBALS['table'];
        $d['dbname'] = $table ;
        $cums = $mydb->begin()->where($d)->getall("ziduanx");
        $dbs = $mydb->begin()->where($d)->getall("ziduan");
        $subject = "自定义字段【".$dbs[0]["discribe"]."】有新的信息";
        $tomail = $dbs[0]["targetmail"];
        //echo $subject ;
        $body = "";
        foreach ($cums as $r)
        {
            $body .= $r['dbdescribe']."(".  $r['dbcum'].")=>".$GLOBALS[$r['dbcum']]."<br>";
            $c[$r['dbcum']]= $GLOBALS[$r['dbcum']];
        }
        $c['createtime'] = date('Y-m-d H:i:s',time());
        //echo $body ;
        $uid = get_cookie('_uid');
        if($uid){
            $c['uid']=$uid;
        }
        $mydb->add($table,$c);

        if($dbs[0]["tixing"]==1)
        {
            load_function('sendmail');
            $mailarr = explode(";", $tomail);
            foreach ($mailarr as $mails) {
                send_mail($mails,$subject,$body);
            }
        }else if($dbs[0]["tixing"]==2)
        {
            $send = load_class("Mail","api");

            $mailarr = explode(";", $tomail);
            foreach ($mailarr as $mails) {
                $send->send($mails,$subject,$body);
            }
        }

        $re['status'] =0 ;
        $re['msg'] = "ok";
        echo json_encode($re);

    }


    public function  sendsms(){

        if(strtolower(trim($GLOBALS['param']))==""){
            exit('{"msg":"验证码错误","status":"1"}');
        }



        load_class('session');
        if($_SESSION['code'] == strtolower(trim($GLOBALS['param']))) {
            //exit('{"info":"验证码正确","status":"y"}');
        } else {
            exit('{"msg":"验证码错误","status":"1"}');
        }



        $api =load_class("alidayu","api");
        $api->send($GLOBALS['mobile']);
        exit('{"msg":"发送成功","status":"0"}');

    }

    public function  checksms(){
        $api =load_class("alidayu","api");
        $count =$api->checksms($GLOBALS['mobile'],$GLOBALS['code']);
        if($count==0){
            exit('{"msg":"验证失败","status":"1"}');
        }else{
            exit('{"msg":"验证通过","status":"0"}');
        }

    }




    public function getlists()
    {

        $db  = load_class("mydb","api");
        $c['cid'] = $GLOBALS['cid'];
        $result = $db->where($c)->getall("category");

        $d['modelid'] = $result[0]['modelid'];
        $result = $db->where($d)->getall("model");
        $table = $result[0]['master_table'];

        $e['cid'] = $GLOBALS['cid'];
        $e['status'] = 9;
        $result =$db->begin()->page($GLOBALS['page'],$GLOBALS['count'])->order("sort DESC,updatetime DESC")->where($e)->getall($table);


        echo json_encode($result);

    }


    public function dongtaijs()
    {
        $cid = $GLOBALS['cid'];
        $page = $GLOBALS['page'];
        $count = $GLOBALS['count'];

        echo "function returnhtml(){";


        echo "}";

    }








}
